package org.neptune.service.rabbit;

import org.neptune.api.entity.CacheBean;
import org.neptune.common.constant.NeptuneConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author lwl
 * @date 2020/10/22 19:06
 */
@Component
public class SeckillDlxProducer {

	private static final Logger logger = LoggerFactory.getLogger(SeckillDlxProducer.class);

	@Autowired
	private AmqpTemplate amqpTemplate;

	public void sender(CacheBean cacheBean) {

		logger.info("producer : seckill userId : {}; seckill seckillId : {}", cacheBean.getUserId(),
				cacheBean.getSeckillId());
		// 发送到死信队列，超时后进入延迟队列
		amqpTemplate.convertAndSend(NeptuneConstant.SECKILL_DELAY_EXCHANGE_NAME,
				NeptuneConstant.SECKILL_DLXQUEUE_ROUTE_KEY, cacheBean);
	}
}
